package org.hxzon.workeasy.components.block;

import org.apache.tapestry5.Link;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.BeginRender;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.PageRenderLinkSource;
import org.hxzon.workeasy.pages.file.TagFile;
import org.hxzon.workeasy.util.WorkEasyUtil;

public class TagBlock {
    @Parameter
    private String tagString;
    @Inject
    private PageRenderLinkSource _pageRenderLinkSource;

    @BeginRender
    void beginRender(MarkupWriter writer) {
        String[] tags = WorkEasyUtil.toTags(tagString);
        for (String tag : tags) {
            Link link = _pageRenderLinkSource.createPageRenderLinkWithContext(TagFile.class, tag, 50, 1);
            writer.element("a", "href", link.toURI());
            writer.write(tag);
            writer.end();
            writer.write(" ");
        }
    }
}
